package com.utime.timesheet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import java.util.Iterator;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class LoginServlet
 */
public class LoginServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	// this is very bad practice
	public static int counter = 0;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public LoginServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		String userLoginId = request.getParameter("userId");

		String userPassword = request.getParameter("password");

		String[] sports = request.getParameterValues("sport");
		
		StringBuilder userSports  = new StringBuilder();
		for (String string : sports) {
			userSports.append(string +"  ");
		}

		System.out.println(" Starting user Req proccessing");
		LoginServlet.counter = counter + 1;

		// first we need to get response writer

		PrintWriter writer = response.getWriter();

		// here u decide u r content is Video

		response.setContentType("text/html");

		writer.write("<html> <body> <h1> Welcome" + userLoginId
				+ "  to our  Servlets tutorial- <br>  You Like  : "
				+ userSports.toString()

				+ "times </h1> </body> </html>");
		writer.close();

	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		doGet(request, response);
	}

	@Override
	public void destroy() {
		System.out.println(" From Destory Method  - adding static code");
	}

	@Override
	public void init() throws ServletException {
		System.out.println(" From Init Method  - ");
	}

}
